package com.kgc.controller;

import com.kgc.common.Result;
import com.kgc.entity.PointsLog;
import com.kgc.entity.PointsRules;
import com.kgc.service.interf.PointsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


// 积分模块
@Controller
@RequestMapping("/apis/points")
public class PointsController {
    @Autowired
    private PointsService pointsService;

    //查看积分规则
    @RequestMapping("/selectIntegralrule")
    public String   selectIntegralrule( ){
        List<PointsRules> pointsRules = pointsService.getPointsRules();
        if (pointsRules!=null){
            return Result.success("200","查询积分规则成功",pointsRules);
        }else {
            return Result.success("400","暂无积分规则");
        }
    }

    //管理员修改积分规则
    @RequestMapping("/updateIntegralrule")
    public String   updateIntegralrule(int ruleID,int pointsValue){
        int i = pointsService.updatePointsRules(ruleID,pointsValue);
        if (i>0){
            return Result.success("200","修改成功");
        }else {
            return Result.success("400","修改失败");
        }
    }

    //管理员手动给用户增加积分
    @RequestMapping("/manuallyaddIntegralrule")
    public String manuallyaddIntegralrule(int userID,int pointsValue){
        int i = pointsService.manuallyaddIntegralrule(userID,pointsValue);
        if (i>0){
            return Result.success("200","积分增加成功");
        }else {
            return Result.success("400","积分增加失败");
        }
    }

    //  用户查询积分流水
    @RequestMapping("/selectuserIntegral")
    public String selectuserIntegral(Integer userID){
        List<PointsLog> pointsFlow = pointsService.getPointsFlow(userID);
        if (pointsFlow!=null){
            return Result.success("200","查询积分流水成功",pointsFlow);
        }else {
            return Result.success("400","查询积分流水失败");
        }
    }



}
